AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')

function ENT:Use(ply, caller)
	if !self.dt.Sparking then
		local plygun = ply:GetActiveWeapon()
		
		if self.dt.Upgrade < 1 then
			if ply:Health() + self.HPHeal < ply:GetMaxHealth() then
					ply:SetHealth(ply:Health() + self.HPHeal)
			else
				ply:SetHealth(ply:GetMaxHealth())
			end
			
			timer.Create(tostring(self) .. "resupply", self.SupplyDelay, 1, self.SetSparking, self, false)
		else
			if ply:Health() + self.Upgrades[1].HPHeal < ply:GetMaxHealth() then
				ply:SetHealth(ply:Health() + self.Upgrades[1].HPHeal)
			else
				ply:SetHealth(ply:GetMaxHealth())
			end	
			
			if ply:Armor() + self.Upgrades[1].ArmorHeal < 100 then
				ply:SetArmor(ply:Armor() + self.Upgrades[1].ArmorHeal)
			else
				ply:SetArmor(100)
			end
		
			timer.Create(tostring(self) .. "resupply", self.Upgrades[1].SupplyDelay, 1, self.SetSparking, self, false)
		end
		
		ply:GiveAmmo(plygun:Clip1() * 2, plygun:GetPrimaryAmmoType())
		
		self.dt.Sparking = true
	end
end

function ENT:OnRemove()
	timer.Destroy(tostring(self) .. "resupply")
end